/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package deatax.card;

import deatax.GameData;
import deatax.Player;
import deatax.Tile;
import java.util.ArrayList;

/**
 *
 * @author pson
 */
public class CardPopulationTax extends CardEffect {

    @Override
    public void run(GameData data, String[] args) {
        ArrayList<Player> players = new ArrayList<Player>();
        if (args[0].equals("All")) {
            players.addAll(data.getRoster().getPlayers());
        } else if (args[0].equals("Self")) {
            players.add(data.getCurrentPlayer());
        } else if (args[0].equals("Other")) {
            players.addAll(data.getRoster().getPlayers());
            players.remove(data.getCurrentPlayer());
        }

            int pc = Integer.parseInt(args[1]);
            for (Player p : players) {
                int total = 0;

                for (Tile t : p.getSettles()) {
                    total += t.getPopulation();
                }
                
                int bonus = (total * pc) / 100;

                if (pc > 0) {
                    data.getGui().addMessage(p, "Receives $" + bonus + " population tax");
                } else {
                    data.getGui().addMessage(p, "Pays $" + (-bonus) + " population tax");
                }
            }
        }
    
}
